package 自定义异常;

public class Login {
    private String userName = "admires";
    private String passWord = "123456";
    public void logInfor(String userName,String passWord)throws UserNameException,PassWordException {//这里不处理异常
        if(!this.userName.equals(userName)){
            throw new UserNameException("用户名错误");
        }
        if(!this.passWord.equals(passWord)){
            throw new PassWordException("密码错误");
        }
        System.out.println("登陆成功");
    }

    public static void main(String[] args) {
        try {
        Login login = new Login();
        login.logInfor("admires1","123456");
    } catch (UserNameException e) {
            e.printStackTrace();
            System.out.println("用户名错误");
        }
        catch (PassWordException e) {
            e.printStackTrace();
            System.out.println("密码错误");
        }

    }
}
